<template>
	<view class="page">
		<pageTxt>
			<!--  v-model="dataList" @query="queryList" -->
			<z-paging ref="paging" refresher-only @onRefresh="onRefresh" :paging-style="{ 'background-color': '#f7f7f7', height: '100%', width: '100%' }">
				<!-- 头部 -->
				<template slot="top">
					<u-navbar title="收款单详情" :autoBack="true" :fixed="false"></u-navbar>
					<view class="tab-box">
						<u-tabs
							:current="tabIndex"
							@click="tabClickFunc"
							:list="tablist"
							inactiveStyle="color: #919092;"
							activeStyle="color: #3B75FF;"
							lineColor="#3B75FF"
						></u-tabs>
					</view>
				</template>
				<!-- 内容 -->
				<view class="detail-content-box" v-if="dataObj">
					<template v-if="tabIndex == 0">
						<u-empty
							v-if="!$fieldShowFunc('61-xmxx') && !$fieldShowFunc('61-skd')"
							marginTop="300rpx"
							icon="https://hzybucket.obs.cn-south-1.myhuaweicloud.com/we_chat/no-msg2.png"
							text=" "
						></u-empty>
						<view class="item-box" v-if="$fieldShowFunc('61-xmxx')">
							<view class="title">项目信息</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sfk_xmmc')">
								<text class="txt">项目名称</text>
								<view class="content">
									{{ dataObj.project_name }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sfk_xmbh')">
								<text class="txt">项目编号</text>
								<view class="content">
									<text class="txt-btn" @click="navToProjectFunc">
										{{ dataObj.project_number || '--' }}
									</text>
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sfk_xmpp')">
								<text class="txt">项目品牌</text>
								<view class="content">
									{{ dataObj.brand_name }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sfk_xmlx')">
								<text class="txt">项目类型</text>
								<view class="content">
									{{ dataObj.store_type_name }}
								</view>
							</view>
						</view>
						<view class="item-box" v-if="$fieldShowFunc('61-skd')">
							<view class="title">收款信息</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sfk_sklx')">
								<text class="txt">收款类型</text>
								<view class="content">
									<template v-if="dataObj.payment_type == 1">勘场费用</template>
									<template v-if="dataObj.payment_type == 2">预付款</template>
									<template v-if="dataObj.payment_type == 3">进度款</template>
									<template v-if="dataObj.payment_type == 4">尾款</template>
									<template v-if="dataObj.payment_type == 5">增项款</template>
									<template v-if="dataObj.payment_type == 6">定金</template>
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sfk_skr')">
								<text class="txt">收款人</text>
								<view class="content">
									{{ dataObj.submitter || '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sfk_skrq')">
								<text class="txt">收款日期</text>
								<view class="content">
									{{ dataObj.review_at || '--' }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sfk_skje')">
								<text class="txt">收款金额</text>
								<view class="content">{{ dataObj.amount_collected }}元</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sfk_skdzt')">
								<text class="txt">收款单状态</text>
								<view class="content">
									<template v-if="dataObj.review_status == 1">待审核</template>
									<template v-if="dataObj.review_status == 2">审核通过</template>
									<template v-if="dataObj.review_status == 3">审核拒绝</template>
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sfk_skzh')">
								<text class="txt">收款账户</text>
								<view class="content">
									{{ dataObj.receiving_account }}
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sfk_skpz')">
								<text class="txt">收款凭证</text>
								<view class="content flex ac flex">
									<image
										v-for="(item, index) in dataObj.voucher_file"
										:key="index"
										:src="$fileImgFunc(item)"
										@click="previewFunc(item)"
										mode="aspectFill"
										class="img-box"
									></image>
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sfk_ysk')">
								<text class="txt">已收款</text>
								<view class="content">{{ dataObj.paid_amount }}元</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sfk_wsk')">
								<text class="txt">未收款</text>
								<view class="content">{{ dataObj.unpaid_amount }}元</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sfk_jsd') && dataObj.payment_type == 4">
								<text class="txt">结算单</text>
								<view class="content">
									<text class="txt-btn">{{ dataObj.settlement_number || '--' }}</text>
								</view>
							</view>
							<view class="item-box-item flex jb" v-if="$fieldShowFunc('sfk_skbz')">
								<text class="txt">备注</text>
								<view class="content">
									{{ dataObj.remark || '--' }}
								</view>
							</view>
						</view>
					</template>
					<!-- 历史记录 -->
					<template v-if="tabIndex == 1">
						<view class="item-box">
							<u-empty
								v-if="!dataObj.log_list.length"
								marginTop="300rpx"
								icon="https://hzybucket.obs.cn-south-1.myhuaweicloud.com/we_chat/no-msg2.png"
								text=" "
							></u-empty>
							<u-steps current="0" direction="column" dot activeColor="#3b75ff" inactiveColor="#3b75ff">
								<u-steps-item v-for="(item, index) in dataObj.log_list" :key="index">
									<template slot="desc">
										<view class="steps-title flex ac jb">
											<view class="steps-title-title">{{ item.updated_at }}</view>
											<view class="steps-title-user-data-box flex ac jc">
												<image class="avater-box" :src="item.handlers_image" mode="aspectFit"></image>
												<view class="user-name u-line-1">
													{{ item.handlers_name + '-' + item.handlers_position }}
												</view>
											</view>
										</view>
										<view class="steps-desc">
											<view class="steps-desc-title">
												{{ item.content }}
											</view>
											<template v-if="[140, 290, 510, 350, 410, 490].includes(item.log_status)">
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('sfk_skje')">
													<view class="steps-desc-box-title">收款金额</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.amount_collected ? item.form_data.amount_collected + '元' : '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('sfk_skzh')">
													<view class="steps-desc-box-title">收款账户</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.account_name || '--' }}
													</view>
												</view>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('sfk_sklx')">
													<view class="steps-desc-box-title">收款类型</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.payment_name || '--' }}
													</view>
												</view>
												<view class="steps-desc-box" v-if="$fieldShowFunc('sfk_skpz')">
													<view class="steps-desc-box-title">收款凭证</view>
													<view class="steps-desc-box-desc flex ac flex-wrap">
														<image
															@click="previewFunc(file)"
															class="img-box"
															v-for="(file, fileIndex) in item.form_data.payment_voucher"
															:key="fileIndex"
															:src="$fileImgFunc(file)"
														></image>
													</view>
												</view>
											</template>
											<template v-else>
												<view class="steps-desc-box flex ac" v-if="$fieldShowFunc('sfk_skbz')">
													<view class="steps-desc-box-title">审批意见</view>
													<view class="steps-desc-box-desc">
														{{ item.form_data.remark || '--' }}
													</view>
												</view>
											</template>
										</view>
									</template>
								</u-steps-item>
							</u-steps>
						</view>
					</template>
				</view>
				<view class="bottom-btn-box flex ac jb" slot="bottom">
					<view style="width: 100%" v-if="!loading">
						<judgeBtn
							info
							unborder
							:per_arr="per_arr"
							objectType="collection"
							:btns="btns"
							:state="dataObj.voucher_status"
							:item="dataObj"
							@change="btnsChange"
						></judgeBtn>
					</view>
				</view>
			</z-paging>
		</pageTxt>
		<!-- 文件预览 -->
		<preFileCom :fileObj="fileObj" @onFileSuccess="fileObj = ''"></preFileCom>
		<!-- 操作组件 -->
		<rePaymentOperate :value.sync="per_name" :oper_item="dataObj" @submit="handleSubmit"></rePaymentOperate>
	</view>
</template>

<script>
export default {
	provide() {
		return {
			providedData: this.btns
		};
	},
	data() {
		return {
			fileObj: '',
			loading: false,
			dataObj: '',
			tabIndex: 0,
			tablist: [
				{
					name: '详情'
				},
				{
					name: '历史记录'
				}
			],
			per_arr: [], //权限列表
			// 操作按钮
			btns: [
				{
					per_name: 'company_preliminaryExamination',
					state: 10,
					name: '收款一审'
				},
				{
					per_name: 'company_reexamineExamination',
					state: 20,
					name: '收款二审'
				},
				{
					per_name: 'company_receiptReviewPassed',
					state: 30,
					name: '收款确认'
				},
				{
					per_name: 'paymentOrder_edit',
					func: (item) => {
						if (item.review_status == 3) {
							return true;
						} else {
							return false;
						}
					},
					name: '重新修改提交'
				}
			],
			per_name: ''
		};
	},
	onLoad(option) {
		this.getReceiptDetails(option.id);
		// 获取权限
		this.$Api
			.getHtmlAuthority({
				path: '/collectionPaymentManagement'
			})
			.then((res) => {
				console.log(res, 'getHtmlAuthority');
				if (res.code == 200) {
					this.per_arr = res.data.permission;
				}
			});
	},
	onShow() {
		if (this.dataObj) {
			this.getReceiptDetails(this.dataObj.voucher_id);
		}
	},
	methods: {
		// 操作反馈
		handleSubmit(e) {
			this.onRefresh();
		},
		// 操作事件
		btnsChange(e) {
			this.per_name = e.per_name;
		},
		onRefresh() {
			this.getReceiptDetails(this.dataObj.voucher_id);
			this.$refs.paging.complete();
		},
		tabClickFunc(e) {
			this.tabIndex = e.index;
		},
		// 详情
		getReceiptDetails(voucher_id) {
			this.loading = true;
			this.$Apipc
				.getReceiptDetails({
					voucher_id
				})
				.then((res) => {
					console.log(res, '收款单详情');
					this.loading = false;
					if (res.code == 200) {
						res.data.log_list.forEach((child) => {
							child.form_data = JSON.parse(child.form_data);
							child.form_data.payment_voucher =
								child.form_data.payment_voucher && child.form_data.payment_voucher.length ? child.form_data.payment_voucher : child.form_data.payment_voucherOld;
						});
						this.dataObj = res.data;
					}
				});
		},
		// 预览
		previewFunc(item) {
			this.fileObj = item;
		},
		// 去详情项目
		navToProjectFunc() {
			uni.navigateTo({
				url: '/pagesB/projectDetail/projectDetail?id=' + this.dataObj.project_id
			});
		}
	}
};
</script>

<style lang="scss" scoped></style>
